package com.jeff.android.lab.architecture.eventbus;

import android.util.Log;

import com.jeff.android.lab.BaseFragment;
import com.jeff.android.lab.architecture.eventbus.event.MessageEvent;
import com.jeff.utils.ToastUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author: duff
 * @date: 2019/4/3
 * @since: 1.0.0
 */
public abstract class EventBusBaseFragment extends BaseFragment {

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMain(MessageEvent event) { // 子类重写了该方法，父类不会回调

        Log.d(TAG, "EventBusBaseFragment.onEventMain");

        if (event.id == 1000) {
            String result = (String) event.object;
            ToastUtil.show(mContext, result);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainBase(MessageEvent event) {

        Log.d(TAG, "EventBusBaseFragment.onEventMainBase");

        if (event.id == 1000) {
            String result = (String) event.object;
            ToastUtil.show(mContext, result);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MessageEvent event) {

        Log.d(TAG, "EventBusBaseFragment.onEvent");

        if (event.id == 1002) {
            String result = (String) event.object;
            ToastUtil.show(mContext, result);
        }
    }

}
